<jsp:include page="logincheck.jsp" />
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="bill" class="se2.Bill" scope="request"/>
<jsp:setProperty name="bill" property="*"/>

<jsp:useBean id="phone" class="se2.PhoneAccount" scope="request"/>
<jsp:setProperty name="phone" property="*"/>

				
				<!-- Initialize the Bill Object -->
				<% 
					GregorianCalendar gc = new GregorianCalendar();
					GregorianCalendar gc2 = new GregorianCalendar();
					
					String start = request.getParameter("generatestart");
					String end = request.getParameter("generateend");
					
					int syear = Integer.parseInt(start.substring(0,4));
					int smonth = Integer.parseInt(start.substring(5,7)) - 1;
					int sday = Integer.parseInt(start.substring(8,10));
					int shour = Integer.parseInt(start.substring(11,13));
					int smin = Integer.parseInt(start.substring(14,16));
					int ssec = Integer.parseInt(start.substring(17,19));
					
					int eyear = Integer.parseInt(end.substring(0,4));
					int emonth = Integer.parseInt(end.substring(5,7)) - 1;
					int eday = Integer.parseInt(end.substring(8,10));
					int ehour = Integer.parseInt(end.substring(11,13));
					int emin = Integer.parseInt(end.substring(14,16));
					int esec = Integer.parseInt(end.substring(17,19));
										
					gc.set(syear, smonth, sday, shour, smin, ssec);
					gc2.set(eyear, emonth, eday, ehour, emin, esec);
					bill.setStartDate(gc);
					bill.setEndDate(gc2);
					bill.setPhoneAccount(Integer.parseInt(request.getParameter("id")));
					bill.getBill();
					
					bill.calculateTotal();
					
					bill.chargeBill();
					
					phone.setId(Integer.parseInt(request.getParameter("id")));
					phone.getPhoneAccountFromDatabase();
					
					phone.setBalance(phone.getBalance() + bill.getTotal());
					phone.updateBalance();
				%>
				
				<jsp:forward page="viewBill.jsp">
				<jsp:param name="id" value="<%= request.getParameter("id") %>" />
				<jsp:param name="cid" value="<%= request.getParameter("cid") %>" />
				</jsp:forward>